package com.walker.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * 配置文件工具类 读取配置文件信息
 */
public class PropertiesUtil {

    private static PropertiesUtil instance;
    
    private static final Properties pro = new Properties();

	private PropertiesUtil() {
		InputStream is;
		try {
			if (isWindows()) {
				is = PropertiesUtil.class.getClass().getResourceAsStream("/application.properties");
			} else {
				is = new FileInputStream(new File(new File("").getAbsoluteFile() + "/application.properties"));
			}
			pro.load(is);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

    public static PropertiesUtil getInstance() {
        if (instance == null) {
            instance = new PropertiesUtil();
        }
        return instance;
    }

    public String getValue(String key) {
        return pro.getProperty(key);
    }

    public int getIntValue(String key) {
        return Integer.parseInt(pro.getProperty(key));
    } 
    
    public boolean getBooleanValue(String key) {
    	return Boolean.parseBoolean(pro.getProperty(key));
    }
    
	public static boolean isWindows() {
		boolean flag = false;
		if (System.getProperties().getProperty("os.name").toUpperCase().indexOf("WINDOWS") != -1) {
			flag = true;
		}
		return flag;
	}
}
